package com.dailyblue.example.project.category.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dailyblue.example.project.bookstore.commons.bean.Category;
import com.dailyblue.example.project.bookstore.commons.mapper.CategoryMapper;
import com.dailyblue.example.project.bookstore.commons.util.JsonResult;
import com.dailyblue.example.project.bookstore.commons.util.ResultTool;
import com.dailyblue.example.project.category.service.CategoryService;
import org.springframework.stereotype.Service;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Override
    public JsonResult findCategory() {
        return ResultTool.success(list());
    }

    @Override
    public JsonResult findCategoryLimit(int limit) {
        QueryWrapper<Category> wrapper = new QueryWrapper<>();
        wrapper.last(" limit " + limit);
        return ResultTool.success(list(wrapper));
    }

    @Override
    public JsonResult findCategoryById(String id) {
        return ResultTool.success(this.getById(id));
    }
}
